<template>
  <view>
    <view class="u-page">
      <!-- 所有内容的容器 -->
      <index v-if="current == 0 && vuex_userInfo.type === 1" />
      <the-ucenter
        v-if="current == 1 && vuex_userInfo.type === 1"
      ></the-ucenter>
      <the-teacher
        :type="vuex_userInfo.type"
        v-if="
          current == 0 && (vuex_userInfo.type === 3 || vuex_userInfo.type === 2)
        "
      ></the-teacher>
      <teacher-center
        v-if="
          current == 1 && (vuex_userInfo.type === 3 || vuex_userInfo.type === 2)
        "
      ></teacher-center>
    </view>
    <!-- 与包裹页面所有内容的元素u-page同级，且在它的下方 -->
    <u-tabbar
      v-model="current"
      :list="list"
      @change="change"
      active-color="#24d7b0"
    ></u-tabbar>
  </view>
</template>

<script>
import Index from "@/pages/index/index";
import TheUcenter from "@/pages/ucenter/ucenter";
import TheTeacher from "@/pages/teacher/teacher";
import TeacherCenter from "@/pages/teacher/center";
import { qiniuyunUrl } from "@/common/config";
export default {
  components: {
    Index,
    TheUcenter,
    TheTeacher,
    TeacherCenter,
  },
  data() {
    return {
      index: 0,
      list: [],
      listParents: [
        {
          iconPath: qiniuyunUrl + "index.png",
          selectedIconPath: qiniuyunUrl + "index_check.png",
          text: "首页",
          customIcon: false,
        },
        {
          iconPath: qiniuyunUrl + "mycenter.png",
          selectedIconPath: qiniuyunUrl + "mycenter_check.png",
          text: "我的",
          customIcon: false,
        },
      ],
      listPrincipal: [
        {
          iconPath: qiniuyunUrl + "index.png",
          selectedIconPath: qiniuyunUrl + "index_check.png",
          text: "班级管理",
          customIcon: false,
        },
        {
          iconPath: qiniuyunUrl + "mycenter.png",
          selectedIconPath: qiniuyunUrl + "mycenter_check.png",
          text: "个人中心",
          customIcon: false,
        },
      ],
      current: 0,
    };
  },
  methods: {
    /**
     * 底部菜单栏 点击
     */
    change(e) {
      this.index = e;
    },
  },
  onShow() {
    if (
      this.vuex_userInfo.hasOwnProperty("type") &&
      this.vuex_userInfo.type != 0
    ) {
      if (this.vuex_userInfo.type === 1) {
        this.list = this.listParents;
      } else if (
        this.vuex_userInfo.type === 3 ||
        this.vuex_userInfo.type === 2
      ) {
        this.list = this.listPrincipal;
      }
    } else {
      uni.reLaunch({
        url: "/pages/regist/register",
      });
    }
  },
};
</script>